package com.cssw.fyzb.busi.api.appeal;

import com.cssw.fyzb.busi.api.task.CollecTask;
import com.cssw.fyzb.core.model.vo.appeal.AddAppealVo;
import com.cssw.fyzb.busi.service.appeal.AppealService;
import com.cssw.fyzb.core.model.dodb.Appeal;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author
 */
@Function(description = "我的申述", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "appealType", type = Type.String, description = "申述类型", required = true),
        @Parameter(name = "contact", type = Type.String, description = "联系电话/QQ", required = true),
        @Parameter(name = "appeal", type = Type.String, description = "申述备注", required = true),
        @Parameter(name = "appealAttach", type = Type.String, description = "申述附件", required = true)
})
@Component
public class SaveAppeal implements Action {

    private final static Logger logger = LoggerFactory.getLogger(CollecTask.class);

    @Autowired
    private AppealService appealService;

    @Override
    public Response execute(Request request) throws Exception {
        try {
            Long userId = request.getLong("userId");
            String appealType = request.getString("appealType");
            String contact = request.getString("contact");
            String appeal = request.getString("appeal");
            String appealAttach = request.getString("appealAttach");
            Long appealId = appealService.saveAppeal(userId, appealType, contact, appeal, appealAttach, Appeal.APPEAL_STATUS_REPRESENTATION);
            return Response.success().put("data", new AddAppealVo(appealId));
        } catch (Exception e) {
            logger.debug("", e);
            return Response.fail("操作失败");
        }
    }
}
